package com.weixin.paleituo.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.util.UIUtils;

/**
 * Author yichao
 * Time  2017/12/11 15:44
 * Dest  登录改版itemView自定义
 */

public class LoginNewItemView extends LinearLayout {

    private LinearLayout mLinearLayout;
    private TextView mTvName,mTvGetMessage;
    private EditText mEtContent;
    private ImageView mIvIcon;
    private View mViewLine;

    public LoginNewItemView(Context context) {
        this(context, null);
    }

    public LoginNewItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        mLinearLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.item_new_login_layout, this, true);
        mTvName = mLinearLayout.findViewById(R.id.tv_name_item_new_login_layout);
        mEtContent = mLinearLayout.findViewById(R.id.et_content_item_new_login_layout);
        mIvIcon = mLinearLayout.findViewById(R.id.iv_del_item_new_login_layout);
        mViewLine=mLinearLayout.findViewById(R.id.view_bottom_lint_item_new_login_layout);
        mTvGetMessage=   mLinearLayout.findViewById(R.id.tv_getmessage_item_new_login_layout);
        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.LoginNewItemView);
        String name = attributes.getString(R.styleable.LoginNewItemView_login_new_item_name);
        if (name != null && !name.equals("")) {
            mTvName.setText(name);
        }
        String detais = attributes.getString(R.styleable.LoginNewItemView_login_new_item_hint_content);
        if (detais != null && !detais.equals("")) {
            mEtContent.setHint(detais);
        }
        boolean showCheckCode = attributes.getBoolean(R.styleable.LoginNewItemView_login_new_item_show_line, true);
        if (showCheckCode){
            mViewLine.setVisibility(VISIBLE);
        }else {
            mViewLine.setVisibility(INVISIBLE);
        }

        boolean isShowIcon = attributes.getBoolean(R.styleable.LoginNewItemView_login_new_item_showIcon, false);
        if (isShowIcon){
            mIvIcon.setVisibility(VISIBLE);
        }else {
            mIvIcon.setVisibility(INVISIBLE);
        }

        attributes.recycle();
        mEtContent.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus){
                    mViewLine.setBackgroundColor(UIUtils.getColor(R.color.c_29CE7E));
                }else {
                    mViewLine.setBackgroundColor(UIUtils.getColor(R.color.c_e5e5e5));
                }
            }
        });


    }

    public LoginNewItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    public EditText getEtContent() {
        return mEtContent;
    }

    public ImageView getIvIcon() {
        return mIvIcon;
    }

    public View getViewLine() {
        return mViewLine;
    }
    public TextView getTvGetMessage(){
        return mTvGetMessage;
    }

    /**
     * 验证码默认状态
     */
    public void setDefaultTvMessageStyle(String tvContent){
        mTvGetMessage.setText(tvContent);
        mTvGetMessage.setEnabled(false);
        mTvGetMessage.setFocusable(false);
        mTvGetMessage.setBackgroundResource(R.drawable.check_code_unfocus_shape);
        mTvGetMessage.setTextColor(UIUtils.getColor(R.color.c_ff383838));
    }
    /**
     * 验证码手机验证成功状态
     * @param tvConten  验证码的内容
     */
    public void setCheckPhoneSuceessTvMessageStyle(String tvConten){
        mTvGetMessage.setText(tvConten);
        mTvGetMessage.setEnabled(true);
        mTvGetMessage.setFocusable(true);
        mTvGetMessage.setBackgroundResource(R.drawable.check_code_focus_shape);
        mTvGetMessage.setTextColor(UIUtils.getColor(R.color.c_ffffffff));
    }

    /**
     * 验证码正在倒计时倒计时
     */
    public void setCountDownTvMessageStyle(String countdown){
        mTvGetMessage.setText(countdown+"秒后获取");
        mTvGetMessage.setEnabled(false);
        mTvGetMessage.setFocusable(false);
        mTvGetMessage.setBackgroundResource(R.drawable.check_code_focus_shape);
        mTvGetMessage.setTextColor(UIUtils.getColor(R.color.c_ffffffff));
    }

    /**
     * 倒计时前
     */
    public void setCountDownBeforTvMessageStyle(){
        mTvGetMessage.setEnabled(false);
        mTvGetMessage.setFocusable(false);
        mTvGetMessage.setBackgroundResource(R.drawable.check_code_focus_shape);
        mTvGetMessage.setTextColor(UIUtils.getColor(R.color.c_ffffffff));

    }













}
